package cn.tedu.boot52.controller;

import cn.tedu.boot52.entity.Emp;
import cn.tedu.boot52.mapper.EmpMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class EmpController {
    @Autowired(required = false)
    EmpMapper empMapper;

    @RequestMapping("/add")
    public void add(Emp emp){
        int i = empMapper.insertEmp(emp);
    }
    @RequestMapping("/selectall")
    public List<Emp> selectAll(){
        List<Emp> emps= empMapper.selectAll();
        return emps;
    }
    @RequestMapping("/selectbyid")
    public Emp selectById(int id){
        Emp emp= empMapper.selectEmpById(id);
        return emp;
    }
    @RequestMapping("/delete")
    public int delete(int id){
        int i = empMapper.deleteEmpById(id);
        if (i==1){
            return 1;
        }
        return 0;
    }
    @RequestMapping("/update")
    public int update(Emp emp){
        int i = empMapper.updateEmpById(emp);
        if (i == 1){
            return 1;
        }
        return 0;
    }
}
